package com.fanfanwang.ffw.app.widget;

import com.fanfanwang.ffw.app.tenant.R;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


/**自定义的是界面头部上面的titleBar*/
public class CommonTitleBar extends LinearLayout {
	private RelativeLayout toolbar_left;
	private TextView toolbar_left_text;
	private TextView toolbar_center_text;
	private TextView toolbar_right_text;
	private RelativeLayout toolbar_right;
	private RelativeLayout toolbar_left_return;
	public CommonTitleBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater.from(context).inflate(R.layout.banner_title_bar_new, this);
		init();
	}

	public static CommonTitleBar getCommonTitleBar(Activity mContext) {
		CommonTitleBar mCommonTitleBar = (CommonTitleBar) mContext
				.findViewById(R.id.common_titlebar);
		return mCommonTitleBar;
	}
	/**
	 * 初始化组件
	 */
	private void init(){
		toolbar_center_text = (TextView)findViewById(R.id.toolbar_center_text);
		toolbar_left_text = (TextView)findViewById(R.id.toolbar_left_text);
		toolbar_right_text = (TextView)findViewById(R.id.toolbar_right_text);
		toolbar_left = (RelativeLayout)findViewById(R.id.toolbar_left);
		toolbar_right = (RelativeLayout)findViewById(R.id.toolbar_right);
		toolbar_left_return=(RelativeLayout)findViewById(R.id.toolbar_return);
	}
	/**
	 * 设置所有的view隐藏
	 */
	public void setAllViewGone(){
		toolbar_right.setVisibility(View.GONE);
		toolbar_left.setVisibility(View.GONE);
		toolbar_center_text.setVisibility(View.GONE);
		toolbar_left_text.setVisibility(View.GONE);
		toolbar_right_text.setVisibility(View.GONE);
	}
	/**
	 * 设置所有的view显示
	 */
	public void setAllViewVisible(){
		toolbar_right.setVisibility(View.VISIBLE);
		toolbar_left.setVisibility(View.VISIBLE);
		toolbar_center_text.setVisibility(View.VISIBLE);
		toolbar_left_text.setVisibility(View.VISIBLE);
		toolbar_right_text.setVisibility(View.VISIBLE);
	}
	/**
	 * 设置左边的按钮
	 * @param name 显示文字
	 * @param l  监听事件
	 */
	public void setLeftView(String name,OnClickListener l){
		toolbar_left.setVisibility(View.VISIBLE);
		toolbar_left_text.setVisibility(View.VISIBLE);
		toolbar_left_text.setText(name);
		toolbar_left.setOnClickListener(l);
	}
	/**
	 * 设置右边的按钮
	 * @param name 显示文字
	 * @param l  监听事件
	 */
	public void setRightView(String name,OnClickListener l){
		toolbar_right.setVisibility(View.VISIBLE);
		toolbar_right_text.setVisibility(View.VISIBLE);
		toolbar_right_text.setText(name);
		toolbar_right.setOnClickListener(l);
	}
	/**
	 * 设置右边的按钮
	 * @param name 显示文字
	 * @param l  监听事件
	 */
	public void setCenterText(String name){
		toolbar_center_text.setVisibility(View.VISIBLE);
		toolbar_center_text.setText(name);
	}
	/**
	 * 设置左边的返回按钮显示
	 * 
	 */
	public void setReturnVisible(){
		toolbar_left_return.setVisibility(View.VISIBLE);
	}
	/**
	 * 设置左边的返回按钮的监听器
	 * 
	 */
	public void setToolBarReturnOnclickListener(OnClickListener l){
		toolbar_left_return.setOnClickListener(l);
	}
}
